package com.lagou.task15;

import org.w3c.dom.ls.LSOutput;

import java.util.*;

public class Student1Test {
    public static void main(String[] args) {
        Student1 s = new Student1("张飞",30);

        Map<Student1,String> m = new HashMap<>();
        //第一种方式 自动调用toString方法
        Object obj = m.put(s,"上海");
        System.out.println(m);

        //方式1 通过keySet() for-each循环
        Set<Student1> student1s = m.keySet();
        for (Student1 s1:student1s){
            System.out.println(s1 + ":" + m.get(s1));
        }
        //方式2 通过Map.Entry for-each循环
        Set<Map.Entry<Student1, String>> sp = m.entrySet();
        for (Map.Entry<Student1, String> mm:sp){
            System.out.println(mm.getKey() + ":" + mm.getValue());

        }
        //方式3 通过keySet取出map数据[Iterator遍历]
        Iterator<Student1> i1 = m.keySet().iterator();//map.keySet()得到的是set集合，可以使用迭代器遍历
        while (i1.hasNext()){
            Student1 key = i1.next();
            System.out.println(key + ":" + m.get(key)) ;

        }
        //通过EntrySet取出map数据[Iterator遍历]
        Iterator<Map.Entry<Student1, String>> is = m.entrySet().iterator();//map.entrySet()得到的是set集合，可以使用迭代器遍历
        while (is.hasNext()){
            Map.Entry<Student1, String> es = is.next();
            System.out.println(es.getKey() + ":" + es.getValue());
        }


        }

    }



